package com.jymj.service.impl;

import com.jymj.dao.ScoreDao;
import com.jymj.entity.CjEntity;
import com.jymj.entity.dto.ComplaintsDto;
import com.jymj.entity.dto.PointPageDto;
import com.jymj.entity.dto.ScorebarDto;
import com.jymj.entity.landmanage.*;
import com.jymj.entity.vo.CompositeVo;
import com.jymj.entity.vo.ScoreVo;
import com.jymj.enumEntity.envior.HjzzejEnum;
import com.jymj.service.EnviorSupvsService;
import com.jymj.service.ScoreService;
import com.jymj.utils.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by ${lc} on 2020/12/11.
 */
@Service
public class ScoreServiceImpl implements ScoreService {
    @Autowired
    private ScoreDao scoreDao;
    @Autowired
    private EnviorSupvsService enviorSupvsService;


    @Override
    public List<ScorebarEntity> queryScorebar(ScorebarDto scorebarDto) {
        return scoreDao.queryScorebar(scorebarDto);
    }

    @Override
    public List<ScoreMonEntity> queryByMon(ScorebarDto scorebarDto) {
        //查询平均分
        List<ScoreMonEntity> scoreMons = scoreDao.queryByMonJf(scorebarDto);
        //查询每月分数
        List<ScoreMonEntity> scoreMonList = scoreDao.queryByMon(scorebarDto);
        for (ScoreMonEntity scoreMon : scoreMons){
            List<ScoreMonEntity> mons = new ArrayList<>();
            for (ScoreMonEntity scoreMon1 : scoreMonList){
                if (scoreMon.getCode().equals(scoreMon1.getCode())){
                    mons.add(scoreMon1);
                }
            }
            scoreMon.setScoreMons(mons);
        }
        return scoreMons;
    }

    @Override
    public List<ScoreZhenEntity> queryRanking(Map<String,Object> params) {
        List<ScoreZhenEntity> scoreZhenEntities = scoreDao.queryRanking(params);
        scoreZhenEntities.sort(Comparator.comparing(ScoreZhenEntity :: getMonaverage).reversed());
        Integer cunCounts = 0;//村数量
        Integer wts = 0;//村本月和以前遗留的问题数
        Integer zfs = 0;//总分数
        Integer szfs = 0;//上月总分数
        Integer scounts = 0;//上月村庄数
        Integer bfCun = 0;//百分村庄数量;
        Integer jsCun = 0;//九十到九十九村庄数量;
        Integer bsCun = 0;//八十到八十九村庄数量;
        Integer qualified = 0;//合格村庄数量
        Integer unqualified = 0;//不合格村庄数量
        Integer zwts = 0;//总问题数
        Integer hjwts = 0;//影响环境问题数
        Integer gcwts = 0;//公厕问题数
        Integer ljwts = 0;//垃圾治理问题数
        Integer wswts = 0;//污水治理问题数
        Integer ldlfwts = 0;//乱堆乱放问题数
        Integer ltlhwts = 0;//乱贴乱画问题数
        Integer sdljwts = 0;//私搭乱建问题数
        Integer gcwtshg = 0;//整改完公厕问题数
        Integer ljwtshg = 0;//整改完垃圾治理问题数
        Integer wswtshg = 0;//整改完污水治理问题数
        Integer ldlfwtshg = 0;//整改完乱堆乱放问题数
        Integer ltlhwtshg = 0;//整改完乱贴乱画问题数
        Integer sdljwtshg = 0;//整改完私搭乱建问题数
        Integer zhgs = 0;//整改完问题数
        Integer pjfCount = 0;//计算总平均分是所需总数

        for (ScoreZhenEntity scoreZhenEntity : scoreZhenEntities) {
            cunCounts+=scoreZhenEntity.getCunCounts();
            wts+=scoreZhenEntity.getWts() == null ? 0 : scoreZhenEntity.getWts();
            zfs+=scoreZhenEntity.getZfs() == null ? 0 : scoreZhenEntity.getZfs();
            szfs+=scoreZhenEntity.getSzfs() == null ? 0 : scoreZhenEntity.getSzfs();
            scounts+=scoreZhenEntity.getScounts() == null ? 0 : scoreZhenEntity.getScounts();
            bfCun+=scoreZhenEntity.getBfCun() == null ? 0 : scoreZhenEntity.getBfCun();
            jsCun+=scoreZhenEntity.getJsCun() == null ? 0 : scoreZhenEntity.getJsCun();
            bsCun+=scoreZhenEntity.getBsCun() == null ? 0 : scoreZhenEntity.getBsCun();
            qualified+=scoreZhenEntity.getQualified() == null ? 0 : scoreZhenEntity.getQualified();
            unqualified+=scoreZhenEntity.getUnqualified() == null ? 0 : scoreZhenEntity.getUnqualified();
            zwts+=scoreZhenEntity.getZwts() == null ? 0 : scoreZhenEntity.getZwts();
            hjwts+=scoreZhenEntity.getHjwts() == null ? 0 : scoreZhenEntity.getHjwts();
            gcwts+=scoreZhenEntity.getGcwts() == null ? 0 : scoreZhenEntity.getGcwts();
            ljwts+=scoreZhenEntity.getLjwts() == null ? 0 : scoreZhenEntity.getLjwts();
            wswts+=scoreZhenEntity.getWswts() == null ? 0 : scoreZhenEntity.getWswts();
            ldlfwts+=scoreZhenEntity.getLdlfwts() == null ? 0 : scoreZhenEntity.getLdlfwts();
            ltlhwts+=scoreZhenEntity.getLtlhwts() == null ? 0 : scoreZhenEntity.getLtlhwts();
            sdljwts+=scoreZhenEntity.getSdljwts() == null ? 0 : scoreZhenEntity.getSdljwts();
            gcwtshg+=scoreZhenEntity.getGcwtshg() == null ? 0 : scoreZhenEntity.getGcwtshg();
            ljwtshg+=scoreZhenEntity.getLjwtshg() == null ? 0 : scoreZhenEntity.getLjwtshg();
            wswtshg+=scoreZhenEntity.getWswtshg() == null ? 0 : scoreZhenEntity.getWswtshg();
            ldlfwtshg+=scoreZhenEntity.getLdlfwtshg() == null ? 0 : scoreZhenEntity.getLdlfwtshg();
            ltlhwtshg+=scoreZhenEntity.getLtlhwtshg() == null ? 0 : scoreZhenEntity.getLtlhwtshg();
            sdljwtshg+=scoreZhenEntity.getSdljwtshg() == null ? 0 : scoreZhenEntity.getSdljwtshg();
            zhgs+=scoreZhenEntity.getZhgs() == null ? 0 : scoreZhenEntity.getZhgs();
            pjfCount += scoreZhenEntity.getPjfCount() == null ? 0 :scoreZhenEntity.getPjfCount();
        }

        ScoreZhenEntity scoreZhenEntity = new ScoreZhenEntity();
        scoreZhenEntity.setPjfCount(pjfCount);
        scoreZhenEntity.setCunCounts(cunCounts);
        scoreZhenEntity.setWts(wts);
        scoreZhenEntity.setZfs(zfs);
        scoreZhenEntity.setSzfs(szfs);
        scoreZhenEntity.setScounts(scounts);
        scoreZhenEntity.setBfCun(bfCun);
        scoreZhenEntity.setJsCun(jsCun);
        scoreZhenEntity.setBsCun(bsCun);
        scoreZhenEntity.setQualified(qualified);
        scoreZhenEntity.setUnqualified(unqualified);
        scoreZhenEntity.setZwts(zwts);
        scoreZhenEntity.setHjwts(hjwts);
        scoreZhenEntity.setGcwts(gcwts);
        scoreZhenEntity.setLjwts(ljwts);
        scoreZhenEntity.setWswts(wswts);
        scoreZhenEntity.setLdlfwts(ldlfwts);
        scoreZhenEntity.setLtlhwts(ltlhwts);
        scoreZhenEntity.setSdljwts(sdljwts);
        scoreZhenEntity.setGcwtshg(gcwtshg);
        scoreZhenEntity.setLjwtshg(ljwtshg);
        scoreZhenEntity.setWswtshg(wswtshg);
        scoreZhenEntity.setLdlfwtshg(ldlfwtshg);
        scoreZhenEntity.setLtlhwtshg(ltlhwtshg);
        scoreZhenEntity.setSdljwtshg(sdljwtshg);
        scoreZhenEntity.setZhgs(zhgs);
        scoreZhenEntity.setZhen("汇总");
        scoreZhenEntities.add(scoreZhenEntity);
        return scoreZhenEntities;
    }
    @Override
    public List<ScorebarEntity> queryZhenCode(String quCode,String date) {
        return scoreDao.queryZhenCode(quCode,date);
    }

    @Override
    public List<PjEnviorSupvsEntity> queryByCode(String code) {
        return scoreDao.queryByCode(code);
    }

    @Override
    public CjEntity selectCjobjByCode(String code) {
        return scoreDao.selectCjobjByCode(code);
    }

    @Override
    public List<ZhenInfo> selectZhen() {
        List<CjInfo> cjList = scoreDao.queryGuding();
        List<ZhenInfo> zhenList = new ArrayList<ZhenInfo>();
        Map<String, List<CjInfo>> zenMap = cjList.stream().collect(Collectors.groupingBy(CjInfo::getZhen));
        for (Map.Entry<String, List<CjInfo>> item : zenMap.entrySet()) {
            ZhenInfo zhenInfo = new ZhenInfo();
            zhenInfo.setZhen(item.getKey());
            //村列表
            List<CjInfo> list = item.getValue();
            //统计问题数量
            zhenInfo.setTotalQuesNum(list.size());
            //统计有问题村数量
            Map<String, List<CjInfo>> cjCounMap = list.stream().collect(Collectors.groupingBy(CjInfo::getCode));
            zhenInfo.setSjczCount(cjCounMap.size());
            //统计二级指标信息
            List ejInfoList = new ArrayList<Map>();
            for (HjzzejEnum ej : HjzzejEnum.values()) {
                HashMap<String, Object> ejHashMap = new HashMap<String, Object>();
                //二级指标标题
                ejHashMap.put("name", ej.getName());
                ejHashMap.put("index", ej.getIndex());
                List<CjInfo> ejList = list.stream().filter(ejItem->{
                    if(ejItem.getHjzzej() == null) {
                        return false;
                    }else {
                        return ejItem.getHjzzej() == ej.getIndex();
                    }
                }).collect(Collectors.toList());
                //二级指标问题数量
                ejHashMap.put("count", ejList.size());
                ejInfoList.add(ejHashMap);
            }
            zhenInfo.setCjList(ejInfoList);
            zhenList.add(zhenInfo);
        }
        System.out.println(zhenList);
        return zhenList;
    }

    @Override
    public List<ZhenInfo> queryZhenCodelist(String quCode,String date) {
        List<CjInfo> cjList = scoreDao.queryZhenCodelist(quCode,date);


        List<ZhenInfo> zhenList = new ArrayList<ZhenInfo>(); //返回给前端用的数据

        Map<String, List<CjInfo>> zenMap = cjList.stream().collect(Collectors.groupingBy(CjInfo::getZhen));
        for (Map.Entry<String, List<CjInfo>> item : zenMap.entrySet()) {
            ZhenInfo zhenInfo = new ZhenInfo();
            zhenInfo.setZhen(item.getKey());
            List<CjInfo> list = item.getValue();
            zhenInfo.setCjList(list);
            List<String> noAverCj = list.stream().filter(cjInfo->{
                return cjInfo.getScore() < 80;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            zhenInfo.setNoAverCj(noAverCj);
            int totalNum = list.stream().mapToInt(CjInfo::getTotalQuesNum).sum();
            zhenInfo.setTotalQuesNum(totalNum);
            int dealQuesNum = list.stream().mapToInt(CjInfo::getDealQuesNum).sum();
            zhenInfo.setDealQuesNum(dealQuesNum);
            if(totalNum ==0){
                zhenInfo.setZhengGailv(0);
            }else{
                zhenInfo.setZhengGailv(dealQuesNum*100/totalNum);

            }
            zhenList.add(zhenInfo);
        }
        return zhenList;
    }

    @Override
    public List<ZhenInfo> queryGuding() {
        List<CjInfo> cjList = scoreDao.queryGuding();
        List<ZhenInfo> zhenList = new ArrayList<ZhenInfo>(); //返回给前端用的数据
        Map<String, List<CjInfo>> zenMap = cjList.stream().collect(Collectors.groupingBy(CjInfo::getZhen));
        for (Map.Entry<String, List<CjInfo>> item : zenMap.entrySet()) {
            ZhenInfo zhenInfo = new ZhenInfo();
            zhenInfo.setZhen(item.getKey());
            List<CjInfo> list = item.getValue();
            zhenInfo.setTotalQuesNum(list.size());
            List<Integer> keyList = Arrays.asList(101,102,103,104,105,106,107,108,109,110,111,112,113,114);
            List<String> noAverCj1 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 101;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj2 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 102;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj3 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 103;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj4 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 104;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj5 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 105;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj6 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 106;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj7 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 107;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj8 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 108;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj9 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 109;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj10 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 110;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj11 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 111;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj12 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 112;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj13 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 113;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            List<String> noAverCj14 = list.stream().filter(cjInfo->{
                return cjInfo.getHjzzej() == 114;
            }).map(cjInfo->cjInfo.getCj()).collect(Collectors.toList());
            list.stream().distinct().forEach(b -> b.getCj());
            ArrayList<CjInfo> collect = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
                    new TreeSet<>(Comparator.comparing(CjInfo::getCj))), ArrayList::new));

            zhenInfo.setCzzthjCount(noAverCj1.size());
            zhenInfo.setComplaintsCount(noAverCj2.size());
            zhenInfo.setSsljCount(noAverCj3.size());
            zhenInfo.setLjwflCount(noAverCj4.size());
            zhenInfo.setJcljCount(noAverCj5.size());
            zhenInfo.setDlljCount(noAverCj6.size());
            zhenInfo.setWszpCount(noAverCj7.size());
            zhenInfo.setGqjcljCount(noAverCj8.size());
            zhenInfo.setGonoCount(noAverCj9.size());
            zhenInfo.setNbshCount(noAverCj10.size());
            zhenInfo.setWsglCount(noAverCj11.size());
            zhenInfo.setLdlfCount(noAverCj12.size());
            zhenInfo.setLtlhCount(noAverCj13.size());
            zhenInfo.setSdljCount(noAverCj14.size());
            zhenInfo.setSjczCount(collect.size());

            zhenList.add(zhenInfo);
        }
        System.out.print(zhenList.toString());
        List<ZhenInfo> zhenListOr = zhenList.stream().sorted(Comparator.comparing(ZhenInfo::getSjczCount).reversed()).collect(Collectors.toList());
        System.out.print(zhenListOr.toString());
        return zhenList;
    }

    @Override
    public List<CjEntity> selectBycjCode() {
        return scoreDao.selectBycjCode();
    }


    @Override
    public void saveCjScorebar(ScorebarEntity scorebarEntity) {
        scoreDao.saveCjScorebar(scorebarEntity);

    }

    @Override
    public void updateScorebar(ScorebarEntity scorebarEntity) {
        scoreDao.updateScorebar(scorebarEntity);

    }

    @Override
    public List<PjEnviorSupvsEntity> queryZgByCode(String code) {
       return scoreDao.queryZgByCode(code);
    }

    @Override
    public void deleteScorebar() {
        scoreDao.deleteScorebar();
    }

    @Override
    public ScoreEntity scoreByCode(CjEntity cjEntity,Integer type) {

        Integer wzgcount = 0;//	未整改问题数
        Integer jsjbs = 0;//	接诉即办件数
        Integer jsjbf = 0;//	接诉即办分
        Integer qjsjbf = 0;//	区接诉即办分
        Integer ljslwjs = 0;//	垃圾设施满冒、渗漏、污迹或破损数
        Integer ljslwjf = 0;//	垃圾设施满冒、渗漏、污迹或破损分
        Integer ljzbghs = 0;//	垃圾设施周边管护不到位数
        Integer ljzbghf = 0;//	垃圾设施周边管护不到位分
        Integer ljwfls = 0;//	未配置垃圾分类桶站和容器标识数
        Integer ljwflf = 0;//	未配置垃圾分类桶站和容器标识分
        Integer ljjcbls = 0;//	暴露垃圾和积存生活垃圾数
        Integer ljjcblf = 0;//	暴露垃圾和积存生活垃圾分
        Integer jzljs = 0;//	建筑垃圾数
        Integer jzljf = 0;//	建筑垃圾分
        Integer ljqss = 0;//	村内街坊路路面清扫保洁不到位、垃圾乱倒乱扔、卫生死角盲区数
        Integer ljqsf = 0;//	村内街坊路路面清扫保洁不到位、垃圾乱倒乱扔、卫生死角盲区分
        Integer wszps = 0;//	生活污水直排溢流路面、乱排乱放数
        Integer wszpf = 0;//	生活污水直排溢流路面、乱排乱放分
        Integer wswcls = 0;//	未经处理的生活污水直接排入河塘沟渠现象数
        Integer wswclf = 0;//	未经处理的生活污水直接排入河塘沟渠现象分
        Integer wsljs = 0;//	沟渠有垃圾、杂物淤积堵塞影响排水数
        Integer wsljf = 0;//	沟渠有垃圾、杂物淤积堵塞影响排水分
        Integer wshcs = 0;//	黑臭水体数
        Integer wshcf = 0;//	黑臭水体分
        Integer gcwkfs = 0;//	未开放数
        Integer gcwkff = 0;//	未开放分
        Integer gcshs = 0;//	公厕设施损坏不能正常使用数
        Integer gcshf = 0;//	公厕设施损坏不能正常使用分
        Integer gczcs = 0;//	公厕存在厕位有污物、脏臭（异味）数
        Integer gczcf = 0;//	公厕存在厕位有污物、脏臭（异味）分
        Integer zdwsqs = 0;//	制度未上墙数
        Integer zdwsqf = 0;//	制度未上墙分
        Integer hgcs = 0;//	旱公厕数
        Integer hgcf = 0;//	旱公厕分
        Integer hhcs = 0;//	旱户厕数
        Integer hhcf = 0;//	旱户厕分
        Integer sdljs = 0;//	私搭乱建数
        Integer sdljf = 0;//	私搭乱建分
        Integer ldlfs = 0;//	乱堆乱放数
        Integer ldlff = 0;//	乱堆乱放分
        Integer jflpssxs = 0;//	街坊路严重破损失修数
        Integer jflpssxf = 0;//	街坊路严重破损失修分
        Integer jflkwjss = 0;//	街坊路坑洼积水现象数
        Integer jflkwjsf = 0;//	街坊路坑洼积水现象分
        Integer lhksphs = 0;//	公共绿化枯死、破坏、占绿毁绿数
        Integer lhksphf = 0;//	公共绿化枯死、破坏、占绿毁绿分
        Integer ltlhs = 0;//	乱贴乱画数
        Integer ltlhf = 0;//	乱贴乱画分
        Integer jkxwxyhs = 0;//	村内架空线杂乱无序交织，存在安全隐患数
        Integer jkxwxyhf = 0;//	村内架空线杂乱无序交织，存在安全隐患分
        Integer ldshs = 0;//	路灯损毁、养护不到位数
        Integer ldshf = 0;//	路灯损毁、养护不到位分
        Integer ldbls = 0;//	路灯不亮数
        Integer ldblf = 0;//	路灯不亮分
        Integer tynyfpws = 0;//	田园堆放农药化肥包装物、废旧农膜等农业投入品废弃物数
        Integer tynyfpwf = 0;//	田园堆放农药化肥包装物、废旧农膜等农业投入品废弃物分
        Integer tyshs = 0;//	田园烧荒现象数
        Integer tyshf = 0;//	田园烧荒现象分
        ScoreEntity scoreEntity = new ScoreEntity();
        scoreEntity.setXzqmc(cjEntity.getXzqmc())
                .setCode(cjEntity.getCode())
                .setZhen(cjEntity.getZhen())
                .setJldate(new Date())
                .setCzlx(cjEntity.getCzlx())
                .setCzdl(cjEntity.getCzdl())
                .setType(type);
        //查询开放情况
        List<PjEnviorSupvsEntity> pjEnviorSupvsEntities = scoreDao.getEnviorSupvsFkqk(cjEntity.getCode(),type);
        Integer wkf = 0;//未开放
        Integer zjwx = 0;//在建 维修
        Integer zckf = 0;//开放
        if (pjEnviorSupvsEntities.size() < 1){
            scoreEntity.setSfkf("-");
        }else {
            for (PjEnviorSupvsEntity pjEnviorSupvsEntity : pjEnviorSupvsEntities) {
                if (type == 1){
                    if (pjEnviorSupvsEntity.getHjzzsj() == 3150){
                        wkf+=1;
                    }
                }
                if (type == 2){
                    if (pjEnviorSupvsEntity.getHjzzsj() == 3150 && pjEnviorSupvsEntity.getQutype() < 5){
                        wkf+=1;
                    }
                    if (pjEnviorSupvsEntity.getHjzzsj() == 3150 && pjEnviorSupvsEntity.getQutype() == 5){
                        zckf+=1;
                    }
                }
                if (pjEnviorSupvsEntity.getHjzzsj() == 3151){
                    zjwx+=1;
                }
                if (pjEnviorSupvsEntity.getHjzzsj() == 3152){
                    zckf+=1;
                }
                if (pjEnviorSupvsEntity.getHjzzsj() == 3153){
                    zckf+=1;
                }
                if (pjEnviorSupvsEntity.getHjzzsj() == 3154){
                    zckf+=1;
                }
                if (pjEnviorSupvsEntity.getHjzzsj() == 3092){
                    zckf+=1;
                }
            }
        }
        if (wkf > 0){
            scoreEntity.setSfkf("未开放");
        }else if (zjwx > 0){
            scoreEntity.setSfkf("在建、维修");
        }else if (zckf > 0){
            scoreEntity.setSfkf("开放");
        }
        //查询数据
        List<PointRecordEntity> pointRecordEntities =
                enviorSupvsService.queryPointList(new PointPageDto().setCode(cjEntity.getCode()));
        scoreEntity.setSfygc(pointRecordEntities.size() > 0);
        List<PjEnviorSupvsEntity> pjList = scoreDao.getEnviorSupvs(cjEntity.getCode(),type);
        if (null == pjList || pjList.size() == 0) {
            List<PjEnviorSupvsEntity> enviorSupvs = scoreDao.getEnviorSupvs(cjEntity.getCode(), 1);
            scoreEntity.setScore(100)
                    .setCounts(enviorSupvs.size() <= 0 ? 0 : enviorSupvs.size())
                    .setYzgcount(enviorSupvs.size() <= 0 ? 0 : enviorSupvs.size())
                    .setWzgcount(0);;
        } else {
            //扣分详情
            for (PjEnviorSupvsEntity enviorSupvsEntity : pjList) {
                if (enviorSupvsEntity.getHjzzsj() == 1150 || enviorSupvsEntity.getHjzzsj() == 1750){
                    ljslwjs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1151 || enviorSupvsEntity.getHjzzsj() == 7151){
                    ljzbghs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1152 || enviorSupvsEntity.getHjzzsj() == 7152){
                    ljwfls += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1153 || enviorSupvsEntity.getHjzzsj() == 7153){
                    ljjcbls += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1154 || enviorSupvsEntity.getHjzzsj() == 7154){
                    jzljs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1155 || enviorSupvsEntity.getHjzzsj() == 7155){
                    ljqss += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1156 || enviorSupvsEntity.getHjzzsj() == 7156){
                    wszps += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1157 || enviorSupvsEntity.getHjzzsj() == 7157){
                    wswcls += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1158 || enviorSupvsEntity.getHjzzsj() == 7158){
                    wsljs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1159 || enviorSupvsEntity.getHjzzsj() == 7159){
                    wshcs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1160 || enviorSupvsEntity.getHjzzsj() == 7160){
                    sdljs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1161 || enviorSupvsEntity.getHjzzsj() == 7161){
                    ldlfs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1162 || enviorSupvsEntity.getHjzzsj() == 7162){
                    jflpssxs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1163 || enviorSupvsEntity.getHjzzsj() == 7163){
                    jflkwjss += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1164 || enviorSupvsEntity.getHjzzsj() == 7164){
                    lhksphs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1165 || enviorSupvsEntity.getHjzzsj() == 7165){
                    ltlhs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1166 || enviorSupvsEntity.getHjzzsj() == 7166){
                    jkxwxyhs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1167 || enviorSupvsEntity.getHjzzsj() == 7167){
                    ldshs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1168 || enviorSupvsEntity.getHjzzsj() == 7168){
                    ldbls += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1169 || enviorSupvsEntity.getHjzzsj() == 7169){
                    tynyfpws += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1170 || enviorSupvsEntity.getHjzzsj() == 7170){
                    tyshs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1171 || enviorSupvsEntity.getHjzzsj() == 7171){
                    hgcs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 1172 || enviorSupvsEntity.getHjzzsj() == 7172){
                    hhcs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 3150){
                    gcwkfs += 1;
                    scoreEntity.setSfkf("未开放");
                }
                if (enviorSupvsEntity.getHjzzsj() == 3152){
                    gcshs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 3153){
                    zdwsqs += 1;
                }
                if (enviorSupvsEntity.getHjzzsj() == 3154){
                    gczcs += 1;
                }
            }
            //垃圾设施满冒、渗漏、污迹或破损
            if (ljslwjs != 0){
                ljslwjf = ljslwjs * -2;
            }
            scoreEntity.setLjslwjs(ljslwjs);
            scoreEntity.setLjslwjf(ljslwjf);
            //垃圾设施周边管护不到位
            if (ljzbghs != 0){
                ljzbghf = ljzbghs * -2;
            }
            scoreEntity.setLjzbghs(ljzbghs);
            scoreEntity.setLjzbghf(ljzbghf);
            //未配置垃圾分类桶站和容器标识
            if (ljwfls != 0){
                ljwflf = ljwfls * -2;
            }
            scoreEntity.setLjwfls(ljwfls);
            scoreEntity.setLjwflf(ljwflf);
            //	暴露垃圾和积存生活垃圾
            if (ljjcbls != 0){
                ljjcblf = ljjcbls * -5;
            }
            scoreEntity.setLjjcbls(ljjcbls);
            scoreEntity.setLjjcblf(ljjcblf);
            //建筑垃圾
            if (jzljs != 0){
                jzljf = jzljs * -2;
            }
            scoreEntity.setJzljs(jzljs);
            scoreEntity.setJzljf(jzljf);
            //村内街坊路路面清扫保洁不到位、垃圾乱倒乱扔、卫生死角盲区
            if (ljqss != 0){
                ljqsf = ljqss * -2;
            }
            scoreEntity.setLjqss(ljqss);
            scoreEntity.setLjqsf(ljqsf);

            //垃圾问题
            if(ljwflf <= -4){
                ljwflf = -4;
            }
            if(ljjcblf <= -10){
                ljjcblf = -10;
            }
            if(jzljf <= -4){
                jzljf = -4;
            }
            if(ljqsf <= -6){
                ljqsf = -6;
            }
            Integer ljmmghf = (ljslwjf + ljzbghf) <= -6 ? -6 : (ljslwjf + ljzbghf);
            scoreEntity.setLjwts(ljslwjs + ljzbghs + ljwfls + ljjcbls + jzljs + ljqss);
            if ((ljmmghf + ljwflf + ljjcblf + jzljf + ljqsf) > -30){
                scoreEntity.setLjwtf(ljmmghf + ljwflf + ljjcblf + jzljf + ljqsf);
            }else {
                scoreEntity.setLjwtf(-30);
            }
            //生活污水直排溢流路面、乱排乱放
            if (wszps != 0){
                wszpf = wszps * -3;
            }
            scoreEntity.setWszps(wszps);
            scoreEntity.setWszpf(wszpf);
            //未经处理的生活污水直接排入河塘沟渠现象
            if (wswcls != 0){
                wswclf = wswcls * -5;
            }
            scoreEntity.setWswcls(wswcls);
            scoreEntity.setWswclf(wswclf);
            //沟渠有垃圾、杂物淤积堵塞影响排水
            if (wsljs != 0){
                wsljf = wsljs * -3;
            }
            scoreEntity.setWsljs(wsljs);
            scoreEntity.setWsljf(wsljf);
            //黑臭水体
            if (wshcs != 0){
                wshcf = wshcs * -3;
            }
            scoreEntity.setWshcs(wshcs);
            scoreEntity.setWshcf(wshcf);
            //污水问题
            if(wszpf <= -9){
                wszpf = -9;
            }
            if(wswclf <= -5){
                wswclf = -5;
            }
            Integer wsgqhcf = (wsljf + wshcf) <= -6? -6 : (wsljf + wshcf);
            scoreEntity.setWswts(wszps + wswcls + wsljs + wshcs);
            if ((wszpf + wswclf + wsgqhcf) > -20){
                scoreEntity.setWswtf(wszpf + wswclf + wsgqhcf);
            }else {
                scoreEntity.setWswtf(-20);
            }
            //未开放
            if (gcwkfs != 0){
                gcwkff = gcwkfs * -10;
            }
            scoreEntity.setGcwkfs(gcwkfs);
            scoreEntity.setGcwkff(gcwkff);
            //公厕设施损坏不能正常使用
            if (gcshs != 0){
                gcshf = gcshs * -2;
            }
            scoreEntity.setGcshs(gcshs);
            scoreEntity.setGcshf(gcshf);
            //公厕存在厕位有污物、脏臭（异味）
            if (gczcs != 0){
                gczcf = gczcs * -2;
            }
            scoreEntity.setGczcs(gczcs);
            scoreEntity.setGczcf(gczcf);
            //制度未上墙
            if (zdwsqs != 0){
                zdwsqf = zdwsqs * -2;
            }
            scoreEntity.setZdwsqs(zdwsqs);
            scoreEntity.setZdwsqf(zdwsqf);
            //旱公厕
            if (hgcs != 0){
                hgcf = hgcs * -5;
            }
            scoreEntity.setHgcs(hgcs);
            scoreEntity.setHgcf(hgcf);
            //旱户厕
            if (hhcs != 0){
                hhcf = hhcs * -1;
            }
            scoreEntity.setHhcs(hhcs);
            scoreEntity.setHhcf(hhcf);
            //公厕问题
            if (hhcf <= -5){
                hhcf = -5;
            }
            Integer gcallf = (gcwkff + gcshf + gczcf + zdwsqf + hgcf) <= -10 ? -10 :
                    (gcwkff + gcshf + gczcf + zdwsqf + hgcf);
            scoreEntity.setGcwts(gcwkfs + gcshs + gczcs + zdwsqs + hgcs + hhcs);
            if ((gcallf + hhcf) > -15){
                scoreEntity.setGcwtf(gcallf + hhcf);
            }else {
                scoreEntity.setGcwtf(-15);
            }
            //私搭乱建
            if (sdljs != 0){
                sdljf = sdljs * -2;
            }
            scoreEntity.setSdljs(sdljs);
            scoreEntity.setSdljf(sdljf);
            //乱堆乱放
            if (ldlfs != 0){
                ldlff = ldlfs * -1;
            }
            scoreEntity.setLdlfs(ldlfs);
            scoreEntity.setLdlff(ldlff);
            //街坊路严重破损失修
            if (jflpssxs != 0){
                jflpssxf = jflpssxs * -2;
            }
            scoreEntity.setJflpssxs(jflpssxs);
            scoreEntity.setJflpssxf(jflpssxf);
            //街坊路坑洼积水现象
            if (jflkwjss != 0){
                jflkwjsf = jflkwjss * -2;
            }
            scoreEntity.setJflkwjss(jflkwjss);
            scoreEntity.setJflkwjsf(jflkwjsf);
            //公共绿化枯死、破坏、占绿毁绿
            if (lhksphs != 0){
                lhksphf = lhksphs * -1;
            }
            scoreEntity.setLhksphs(lhksphs);
            scoreEntity.setLhksphf(lhksphf);
            //乱贴乱画
            if (ltlhs != 0){
                ltlhf = ltlhs * -1;
            }
            scoreEntity.setLtlhs(ltlhs);
            scoreEntity.setLtlhf(ltlhf);
            //村内架空线杂乱无序交织，存在安全隐患
            if (jkxwxyhs != 0){
                jkxwxyhf = jkxwxyhs * -1;
            }
            scoreEntity.setJkxwxyhs(jkxwxyhs);
            scoreEntity.setJkxwxyhf(jkxwxyhf);
            //路灯损毁、养护不到位
            if (ldshs != 0){
                ldshf = ldshs * -1;
            }
            scoreEntity.setLdshs(ldshs);
            scoreEntity.setLdshf(ldshf);
            //路灯不亮
            if (ldbls != 0){
                ldblf = ldbls * -1;
            }
            scoreEntity.setLdbls(ldbls);
            scoreEntity.setLdblf(ldblf);
            //田园堆放农药化肥包装物、废旧农膜等农业投入品废弃物
            if (tynyfpws != 0){
                tynyfpwf = tynyfpws * -1;
            }
            scoreEntity.setTynyfpws(tynyfpws);
            scoreEntity.setTynyfpwf(tynyfpwf);
            //田园烧荒现象
            if (tyshs != 0){
                tyshf = tyshs * -1;
            }
            scoreEntity.setTyshs(tyshs);
            scoreEntity.setTyshf(tyshf);
            //村容问题数
            if (sdljf <= -6){
                sdljf = -6;
            }
            if (ldlff <= -5){
                ldlff = -5;
            }
            if (lhksphf <= -4){
                lhksphf = -4;
            }
            if (ltlhf <= -3){
                ltlhf = -3;
            }
            if (jkxwxyhf <= -3){
                jkxwxyhf = -3;
            }
            Integer jflf = (jflpssxf + jflkwjsf) <= -4 ? -4 : (jflpssxf + jflkwjsf);
            Integer ldf = (ldshf + ldblf) <= -3 ? -3 : (ldshf + ldblf);
            Integer tyf = (tynyfpwf + tyshf) <= -2 ? -2 : (tynyfpwf + tyshf);
            scoreEntity.setCrwts(sdljs + ldlfs + jflpssxs + jflkwjss + lhksphs + ltlhs +
                    jkxwxyhs + ldshs + ldbls + tynyfpws + tyshs);
            if ((sdljf + ldlff + jflf + lhksphf + ltlhf +
                    jkxwxyhf + ldf + tyf) > -30){
                scoreEntity.setCrwtf(sdljf + ldlff + jflf + lhksphf + ltlhf +
                        jkxwxyhf + ldf + tyf);
            }else {
                scoreEntity.setCrwtf(-30);
            }
            //接诉即办
            //List<ComplaintsDto> complaintsDtos = scoreDao.getJsjb(cjEntity.getCode());
            /*for (ComplaintsDto complaintsDto : complaintsDtos) {
                jsjbs += 1;
                if (!complaintsDto.getSolve()){
                    wzgcount +=1;
                }
            }
            jsjbf = jsjbs == 0 ? 0 : -5;*/
            //scoreEntity.setJsjbs(complaintsDtos.size());
            //scoreEntity.setJsjbf(jsjbf+ qjsjbf);
            //逾期整改数
            scoreEntity.setYqzgs(scoreDao.queryYqzgs(cjEntity.getCode()));
            //计算总数量 分数
            scoreEntity.setCounts(scoreDao.getEnviorSupvs(cjEntity.getCode(),1).size());
            scoreEntity.setWzgcount(scoreDao.getEnviorSupvs(cjEntity.getCode(),2).size() + wzgcount);
            Integer yzg =scoreEntity.getCounts() - scoreEntity.getWzgcount();
            scoreEntity.setYzgcount(yzg == null ? 0 : yzg);
            scoreEntity.setScore(100 + jsjbf + scoreEntity.getLjwtf() + scoreEntity.getWswtf() +
                    scoreEntity.getGcwtf() + scoreEntity.getCrwtf() + jsjbf);
        }
        return scoreEntity;
    }

    @Override
    public void save(ScoreEntity scoreEntity) {
        scoreDao.save(scoreEntity);
    }

    @Override
    public List<ScoreEntity> getScore(ScorebarDto scorebarDto) {
        return scoreDao.queryScore(scorebarDto);
    }

    @Override
    public List<ScoreVo> getZhscore(ScorebarDto scorebarDto) {
        return scoreDao.getZhscore(scorebarDto);
    }

    @Override
    public List<ToiletRecordEntity> queryRecord(ScorebarDto scorebarDto) {
        List<ToiletRecordEntity> toiletRecordEntities = new ArrayList<>();
        List<PointRecordEntity> pointRecordEntities = scoreDao.queryRecord(scorebarDto);
        for (PointRecordEntity pointRecordEntity : pointRecordEntities) {
            ToiletRecordEntity toiletRecordEntity = new ToiletRecordEntity();
            List<PjEnviorSupvsEntity> supvsEntities = scoreDao.queryEnvior(pointRecordEntity.getId());
            if (supvsEntities == null || supvsEntities.size() ==0){
                toiletRecordEntity.setScore(100)
                        .setJldate(new Date())
                        .setGddwid(Long.valueOf(pointRecordEntity.getId()));
            }else{
                Integer wkf = 0;//未开放
                Integer zckf = 0;//开放
                Integer zjwx = 0;//在建 维修
                Integer zdsq = 0;//制度上墙
                Integer sssh = 0;//设施损坏
                Integer wswt = 0;//卫生问题
                Integer sfzg = 0;//是否整改
                for (PjEnviorSupvsEntity supvsEntity : supvsEntities) {
                    //计算公厕问题数
                    if (supvsEntity.getHjzzsj() == 3092){
                        zckf+=1;
                    }
                    if (supvsEntity.getHjzzsj() == 3150 && supvsEntity.getZjwj() != 1){
                        wkf+=1;
                    }
                    if (supvsEntity.getHjzzsj() == 3151){
                        zjwx+=1;
                    }
                    if (supvsEntity.getHjzzsj() == 3152){
                        sssh+=1;
                    }
                    if (supvsEntity.getHjzzsj() == 3153){
                        zdsq+=1;
                    }
                    if (supvsEntity.getHjzzsj() == 3154){
                        wswt+=1;
                    }
                    if (supvsEntity.getQutype() < 5 && supvsEntity.getHjzzsj() != 3092
                            && supvsEntity.getHjzzsj() != 3151){
                        sfzg+=1;
                    }
                }
                toiletRecordEntity = new ToiletRecordEntity();
                toiletRecordEntity.setPointRecordEntity(pointRecordEntity)
                        .setSfkf(wkf <= 0)
                        .setGddwid(Long.valueOf(pointRecordEntity.getId()))
                        .setZdsq(zdsq)
                        .setSssh(sssh)
                        .setWswt(wswt)
                        .setWkfs(wkf)
                        .setJldate(new Date())
                        .setZjwx(zjwx)
                        .setZjwx1(zjwx > 0)
                        .setZckf(zckf > 0 || (sssh + zdsq + wswt) > 0)
                        .setWzckf(wkf > 0);
                if (sfzg > 0){
                    toiletRecordEntity.setRemark(sfzg+"个未整改");
                }else if ((sssh + zdsq + wswt) == 0){
                    toiletRecordEntity.setRemark("");
                }else {
                    toiletRecordEntity.setRemark("已整改");
                }
                //计算分数
                if (wkf > 0){
                    toiletRecordEntity.setScore(0);
                }else if (zjwx > 0 && wkf <= 0 && sssh <= 0 && zdsq <= 0 && wswt <= 0){
                    toiletRecordEntity.setScore(null);
                } else{
                    Integer score = (zdsq + sssh + wswt) * -2;
                    toiletRecordEntity.setScore(100 + score);
                }
            }
            toiletRecordEntities.add(toiletRecordEntity);
        }
        return toiletRecordEntities;
    }


    @Override
    public void saveToiletRecord(List<ToiletRecordEntity> toiletRecordEntities) {
        scoreDao.saveToiletRecord(toiletRecordEntities);
    }

    @Override
    public List<PointRecordEntity> getToiletRecord(ScorebarDto scorebarDto) {
        return scoreDao.getToiletRecord(scorebarDto);
    }

    @Override
    public void saveScoreTotal(List<ScoreVo> scoreVos) {
        scoreDao.saveScoreTotal(scoreVos);
    }

    @Override
    public List<ScoreVo> queryZhscore(ScorebarDto scorebarDto) {
        return scoreDao.queryZhscore(scorebarDto);
    }

    @Override
    public List<CompositeVo> getZhdf(String date,Integer type) {
        List<CompositeVo> compositeVos = new ArrayList<>();
        CompositeVo compositeVo = new CompositeVo();
        if (type == null){
            return null;
        }
        if (type == 3){
            compositeVos = scoreDao.getZhdf(date);
            compositeVo = scoreDao.getQzhdf(date);
        }else {
            compositeVos = scoreDao.getJcdf(date,type);
            compositeVo = scoreDao.getQjcdf(date,type);
        }
        if (compositeVos.size() == 0){
            throw new RRException("暂无数据");
        }
        compositeVo.setZhen("通州区");
        compositeVos.add(0,compositeVo);
        return compositeVos;
    }


    @Override
    public ScorebarEntity scorebarByCode(CjEntity cjEntity,Integer type) {

        Integer score = 0;//	最终得分
        Integer zthjqkf = 0;//	整体环境扣分
        Integer tswts = 0;//	12345投诉问题数
        Integer tswtf = 0;//	12345投诉问题扣分
        Integer gcf = 0;//	公厕扣分
        Integer nbss = 0;//	内部设施损坏问题数
        Integer nbssf = 0;//	内部设施损坏扣分
        Integer zdsqs = 0;//	制度上墙问题数
        Integer zdsqf = 0;//	制度上墙扣分
        Integer wswts = 0;//	卫生问题数
        Integer wswtf = 0;//	卫生问题扣分
        Integer ljss = 0;//	村内垃圾收集设施干净完好问题数
        Integer ljssf = 0;//	村内垃圾收集设施干净完好问题扣分
        Integer ljrqs = 0;//	村内垃圾日产日清问题数
        Integer ljrqf = 0;//	村内垃圾日产日清问题扣分
        Integer dlzjs = 0;//	村内道路干净整洁问题数
        Integer dlzjf = 0;//	村内道路干净整洁问题扣分
        Integer wszps = 0;//	村内污水直排流溢问题数
        Integer wszpf = 0;//	村内污水直排流溢问题扣分
        Integer dshcs = 0;//	排水沟堵塞、积存垃圾 黑臭水体问题数
        Integer dshcf = 0;//	沟渠堵塞淤积黑臭水体问题扣分
        Integer ldlfs = 0;//	乱堆乱放问题数
        Integer ldlff = 0;//	乱堆乱放扣分
        Integer ltlhs = 0;//	乱贴乱画问题数
        Integer ltlhf = 0;//	乱贴乱画扣分
        Integer sdljs = 0;//	私搭乱建问题数
        Integer sdljf = 0;//	私搭乱建扣分
        Integer gczs = 0;//	公厕总问题数
        Integer gcfxj = 0;//	公厕扣分小计
        Integer shljs = 0;//	生活垃圾问题数
        Integer ljmswp = 0;//垃圾满冒 渗漏 污迹 破损问题数
        Integer ljmswpf = 0;//垃圾满冒 渗漏 污迹 破损扣分
        Integer ljzbgh = 0;//垃圾周边管护
        Integer ljzbghf = 0;//垃圾周边管护扣分
        Integer dcz = 0;//地搓站
        Integer dczf = 0;//地搓站扣分
        Integer ljfl = 0;//垃圾分类
        Integer ljflf = 0;//垃圾分类扣分
        Integer jcshlj = 0;//积存生活垃圾
        Integer jcshljf = 0;//积存生活垃圾扣分
        Integer jzlj = 0;//建筑垃圾
        Integer jzljf = 0;//建筑垃圾扣分
        Integer clsdlj = 0;//存量私搭乱建
        Integer clsdljf = 0;//存量私搭乱建扣分
        Integer xzsdljf = 0;//新增私搭乱建扣分
        Integer xzsdlj = 0;//新增私搭乱建
        Integer hcs = 0;//旱厕
        Integer wxdjl = 0;//无消毒记录
        Integer yxdjl = 0;//有消毒记录
        Integer ywgc = 0;//有无公厕
        Integer zckf = 0;
        Integer wzckfs = 0;//未正常开放数

        Integer hssts = 0;//    黑臭水体
        Integer pscjljs =0;//    排水沟堵塞、积存垃圾数量
        Integer ljssmms = 0;//垃圾设施满冒数
        Integer ljssslwzs=0;//垃圾设施渗漏、污迹
        Integer ljssshs = 0;//垃圾设施破损
        Integer gcsxshs = 0;//公厕上下水设施损坏
        Integer zbdkshs = 0;//公厕座便、蹲位设施损坏
        Integer xscshs = 0;//公厕洗手池设施损坏
        Integer bcdwzws =0;//公厕便槽蹲位脏污
        Integer dmzws =0;//公厕地面脏污
        Integer fcmys =0;//公厕粪池满溢
        Integer wzds =0;//无制度
        Integer zdwsqs =0;//制度未上墙


        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        ScorebarEntity scorebarEntity = new ScorebarEntity();
        List<PjEnviorSupvsEntity> pjList = new ArrayList<>();
        if (type == 1) {
            pjList = queryByCode(cjEntity.getCode());
        }
        if (type == 2){
            pjList = queryZgByCode(cjEntity.getCode());
        }
        scorebarEntity.setType(type);
        scorebarEntity.setCode(cjEntity.getCode());
        scorebarEntity.setXzqmc(cjEntity.getXzqmc());
        scorebarEntity.setZhen(cjEntity.getZhen());
        scorebarEntity.setZhencode(cjEntity.getZhencode());
        scorebarEntity.setCzlx(cjEntity.getCzlx() == null ? "": cjEntity.getCzlx());
        scorebarEntity.setCzdl(cjEntity.getCzdl() == null ? "": cjEntity.getCzdl());
        List<PointRecordEntity> pointRecordEntities =
                enviorSupvsService.queryPointList(new PointPageDto().setCode(cjEntity.getCode()));
        scorebarEntity.setYwgc(pointRecordEntities.size() > 0 ? 1: 0);

        if (null == pjList || pjList.size() == 0) {
            List<PjEnviorSupvsEntity> pjEnviorSupvsEntities = queryMwtByCode(cjEntity.getCode());
            if (pjEnviorSupvsEntities != null  && pjEnviorSupvsEntities.size() > 0){
                scorebarEntity.setScore(100);
            }else {
                scorebarEntity.setScore(0);
            }
            scorebarEntity.setJldate(new Date());
        } else {
            for (PjEnviorSupvsEntity pjentiy : pjList) {
                if (pjentiy.getHjzzsj() == 1012) {
                    zthjqkf = -2;
                    scorebarEntity.setZthjqk(pjentiy.getHjzzsj());
                    scorebarEntity.setZthjqkf(zthjqkf);
                } else  if (pjentiy.getHjzzsj() == 1013){
                    zthjqkf = -4;
                    scorebarEntity.setZthjqk(pjentiy.getHjzzsj());
                    scorebarEntity.setZthjqkf(zthjqkf);
                }
                if (pjentiy.getHjzzsj() == 1022 || pjentiy.getHjzzsj() == 7022){
                    tswts += 1;
                }
                if (pjentiy.getHjzzsj() == 1031 || pjentiy.getHjzzsj() == 1032 ||pjentiy.getHjzzsj() == 1033 ||
                        pjentiy.getHjzzsj() == 7031 || pjentiy.getHjzzsj() == 7032 ||pjentiy.getHjzzsj() == 7033){
                    ljmswp += 1;
                }
                if (pjentiy.getHjzzsj() == 1031 || pjentiy.getHjzzsj() == 7031){
                    ljssmms +=1;
                }
                if (pjentiy.getHjzzsj() == 1032 || pjentiy.getHjzzsj() == 7032){
                    ljssslwzs +=1;
                }
                if (pjentiy.getHjzzsj() == 1033 || pjentiy.getHjzzsj() == 7033){
                    ljssshs +=1;
                }
                if (pjentiy.getHjzzsj() == 1034 || pjentiy.getHjzzsj() == 7034){
                    ljzbgh += 1;
                }
                if (pjentiy.getHjzzsj() == 1035 || pjentiy.getHjzzsj() == 7035){
                    dcz += 1;
                }
                if (pjentiy.getHjzzsj() == 1051 || pjentiy.getHjzzsj() == 7051){
                    ljfl += 1;
                }
                if (pjentiy.getHjzzsj() == 1052 || pjentiy.getHjzzsj() == 7052){
                    jcshlj += 1;
                }
                if (pjentiy.getHjzzsj() == 1054 || pjentiy.getHjzzsj() == 7054){
                    jzlj += 1;
                }
                if (pjentiy.getHjzzsj() == 1061 || pjentiy.getHjzzsj() == 7061){
                    dlzjs += 1;
                }
                if (pjentiy.getHjzzsj() == 1071 || pjentiy.getHjzzsj() == 7071){
                    wszps += 1;
                }
                if (pjentiy.getHjzzsj() == 1081 || pjentiy.getHjzzsj() == 1082 ||
                        pjentiy.getHjzzsj() == 7081 || pjentiy.getHjzzsj() == 7082){
                    dshcs += 1;
                }
                if (pjentiy.getHjzzsj() == 1081 || pjentiy.getHjzzsj() == 7081){
                    hssts +=1;
                }
                if (pjentiy.getHjzzsj() == 1082 || pjentiy.getHjzzsj() == 7082){
                    pscjljs +=1;
                }
                if (pjentiy.getHjzzsj() == 3091){
                    wzckfs += 1;
                    gcf = -10;
                }
                if (pjentiy.getHjzzsj() == 3092){
                    scorebarEntity.setSfkf(3092);
                    zckf += 1;
                }
                if (pjentiy.getHjzzsj() == 1144 || pjentiy.getHjzzsj() == 7144){
                    scorebarEntity.setSfhc(1);
                    hcs += 1;

                }
                if (pjentiy.getHjzzsj() == 3101 || pjentiy.getHjzzsj() == 3102 || pjentiy.getHjzzsj() == 3103){
                    nbss += 1;
                }
                if (pjentiy.getHjzzsj() == 3101){
                    gcsxshs +=1;
                }
                if (pjentiy.getHjzzsj() == 3102){
                    zbdkshs +=1;
                }
                if (pjentiy.getHjzzsj() == 3103){
                    xscshs +=1;
                }
                if (pjentiy.getHjzzsj() == 3111 || pjentiy.getHjzzsj() == 3112 || pjentiy.getHjzzsj() == 3113){
                    wswts += 1;
                }
                if (pjentiy.getHjzzsj() == 3111){
                    bcdwzws+=1;
                }
                if (pjentiy.getHjzzsj() == 3112){
                    dmzws+=1;
                }
                if (pjentiy.getHjzzsj() == 3113){
                    fcmys+=1;
                }
                if (pjentiy.getHjzzsj() == 3114 || pjentiy.getHjzzsj() == 3115){
                    zdsqs += 1;
                }
                if (pjentiy.getHjzzsj() == 3114){
                    wzds +=1;
                }
                if (pjentiy.getHjzzsj() == 3115){
                    zdwsqs +=1;
                }
                if (pjentiy.getHjzzsj() == 1121 || pjentiy.getHjzzsj() == 7121){
                    ldlfs += 1;
                }
                if (pjentiy.getHjzzsj() == 1131 || pjentiy.getHjzzsj() == 7131){
                    ltlhs += 1;
                }
                if (pjentiy.getHjzzsj() == 1142 || pjentiy.getHjzzsj() == 7142){
                    clsdlj += 1;
                }
                if (pjentiy.getHjzzsj() == 1143 || pjentiy.getHjzzsj() == 7143){
                    xzsdlj += 1;
                }
                if (pjentiy.getHjzzsj() == 3116){
                    yxdjl += 1;
                }
                if (pjentiy.getHjzzsj() == 3117){
                    wxdjl += 1;
                }
            }
            if (gcf < 0){
                scorebarEntity.setSfkf(3091);
            }
            scorebarEntity.setWzckfs(wzckfs);
            if (tswts ==1){
                tswtf = -3;
            }else if (tswts > 1){
                tswtf = -6;
            }
            scorebarEntity.setTswts(tswts);
            scorebarEntity.setTswtf(tswtf);
            if (ljmswp != 0){
                ljmswpf = ljmswp * -2;
            }
            scorebarEntity.setLjmswp(ljmswp);
            scorebarEntity.setLjmswpf(ljmswpf);
            if (ljzbgh != 0){
                ljzbghf = ljzbgh * -2;
            }
            scorebarEntity.setLjzbgh(ljzbgh);
            scorebarEntity.setLjzbghf(ljzbghf);
            if (dcz != 0){
                dczf = dcz * -3;
            }
            scorebarEntity.setDcz(dcz);
            scorebarEntity.setDczf(dczf);
            if (ljfl != 0){
                ljflf = -3;
            }
            scorebarEntity.setLjfl(ljfl);
            scorebarEntity.setLjflf(ljflf);
            if (jcshlj == 1){
                jcshljf = -2;
            }else if (jcshlj == 2){
                jcshljf = -4;
            }else if (jcshlj >= 3){
                jcshljf = -8;
            }
            scorebarEntity.setJcshlj(jcshlj);
            scorebarEntity.setJcshljf(jcshljf);
            if (jzlj == 1){
                jzljf = -2;
            }else if (jzlj >= 2){
                jzljf = -5;
            }
            scorebarEntity.setJzlj(jzlj);
            scorebarEntity.setJzljf(jzljf);
            ljss = ljmswp + ljzbgh + dcz;
            if ((ljmswpf + ljzbghf + dczf) >= -12){
                ljssf = ljmswpf + ljzbghf + dczf;
            }else {
                ljssf = -12;
            }
            scorebarEntity.setLjss(ljss);
            scorebarEntity.setLjssf(ljssf);
            ljrqs = jcshlj + jzlj;
            if ((jcshljf + jzljf) >= -10){
                ljrqf = jcshljf + jzljf;
            }else {
                ljrqf = -10;
            }
            scorebarEntity.setLjrqs(ljrqs);
            scorebarEntity.setLjrqf(ljrqf);
            if ((dlzjs * 2) <= 5){
                dlzjf = dlzjs * -2;
            }else {
                dlzjf = -5;
            }
            scorebarEntity.setDlzjs(dlzjs);
            scorebarEntity.setDlzjf(dlzjf);
            scorebarEntity.setShljs(ljss + ljrqs + dlzjs + ljfl);
            scorebarEntity.setShljf(ljssf + ljrqf + dlzjf + ljflf);

            if ((wszps * 2) <= 10){
                wszpf = wszps * -2;
            }else {
                wszpf = -10;
            }
            scorebarEntity.setWszps(wszps);
            scorebarEntity.setWszpf(wszpf);
            if ((dshcs * 2) <=  10){
                dshcf = dshcs * -2;
            }else {
                dshcf = -10;
            }
            scorebarEntity.setDshcs(dshcs);
            scorebarEntity.setDshcf(dshcf);
            scorebarEntity.setShwss(wszps + dshcs);
            scorebarEntity.setShwsf(wszpf + dshcf);

            scorebarEntity.setGcf(gcf);
            if (nbss != 0){
                nbssf = nbss * -1;
            }
            scorebarEntity.setNbss(nbss);
            scorebarEntity.setNbssf(nbssf);
            if (wswts != 0){
                wswtf = wswts * -1;
            }
            scorebarEntity.setWswts(wswts);
            scorebarEntity.setWswtf(wswtf);
            if (zdsqs != 0){
                zdsqf = -1;
            }
            scorebarEntity.setZdsqs(zdsqs);
            scorebarEntity.setZdsqf(zdsqf);
            if (gcf != 0){
                gcfxj = -10;
            }else if ((nbssf + wswtf + zdsqf) >= -10){
                gcfxj = nbssf + wswtf + zdsqf;
            }else {
                gcfxj = -10;
            }
            scorebarEntity.setGcfxj(gcfxj);
            scorebarEntity.setGczs(nbss + wswts + zdsqs + wzckfs + wxdjl);

            if (ldlfs <= 10){
                ldlff = ldlfs * -1;
            }else {
                ldlff = -10;
            }
            scorebarEntity.setLdlfs(ldlfs);
            scorebarEntity.setLdlff(ldlff);
            if (ltlhs <= 4){
                ltlhf = ltlhs * -1;
            }else {
                ltlhf = -4;
            }
            scorebarEntity.setLtlhs(ltlhs);
            scorebarEntity.setLtlhf(ltlhf);
            if (clsdlj != 0){
                clsdljf = clsdlj * -2;
            }
            scorebarEntity.setClsdlj(clsdlj);
            scorebarEntity.setClsdljf(clsdljf);
            if (xzsdlj != 0){
                xzsdljf = xzsdlj * -4;
            }
            Integer hcf = hcs * -2;
            scorebarEntity.setXzsdlj(xzsdlj);
            scorebarEntity.setXzsdljf(xzsdljf);
            if ((clsdljf + xzsdljf + hcf) >= -16){
                sdljf = clsdljf + xzsdljf + hcf;
            }else {
                sdljf = -16;
            }
            scorebarEntity.setSdljs(clsdlj + xzsdlj + hcs);
            scorebarEntity.setSdljf(sdljf);
            scorebarEntity.setHcs(hcs);

            score = 100 + zthjqkf + tswtf + gcfxj + ljssf + ljrqf +
                    dlzjf + ljflf + wszpf + dshcf + ldlff + ltlhf + sdljf;

            scorebarEntity.setCounts(pjList.size() - yxdjl - zckf);
            scorebarEntity.setYxdjl(yxdjl);
            scorebarEntity.setWxdjl(wxdjl);
            scorebarEntity.setJldate(new Date());
            scorebarEntity.setScore(score);

            scorebarEntity.setHssts(hssts);
            scorebarEntity.setLjssmms(pscjljs);
            scorebarEntity.setLjssmms(ljssmms);
            scorebarEntity.setLjssslwzs(ljssslwzs);
            scorebarEntity.setLjssshs(ljssshs);
            scorebarEntity.setGcsxshs(gcsxshs);
            scorebarEntity.setZbdkshs(zbdkshs);
            scorebarEntity.setXscshs(xscshs);
            scorebarEntity.setBcdwzws(bcdwzws);
            scorebarEntity.setFcmys(fcmys);
            scorebarEntity.setDmzws(dmzws);
            scorebarEntity.setWzds(wzds);
            scorebarEntity.setZdwsqs(zdwsqs);
        }
        return scorebarEntity;
    }

    private List<PjEnviorSupvsEntity> queryMwtByCode(String code) {
        return scoreDao.queryMwtByCode(code);
    }


}
